package com.hp.bon.sgw.wh.channel.groupConsistency.BizSlot;

import com.hp.bon.sgw.wh.channel.common.BizConsts;
import com.hp.bon.sgw.wh.channel.common.BizParam;
import com.hp.bon.sgw.wh.channel.common.BizResult;
import com.hp.bon.sgw.wh.channel.invoices.BizSlot;
import com.hp.bon.sgw.wh.channel.invoices.bizSlot.HttpClientUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @PROJECT_NAME: SGW_WH2.1_TMALL
 * @DESCRIPTION:
 * @USER: YouQi
 * @DATE: 2021/5/20 17:32
 */
public class CreditProdFeeSlot implements BizSlot {
    private static final Logger _log = LoggerFactory.getLogger(CreditProdFeeSlot.class);

    @Override
    public BizResult doBiz(BizParam bizParam) {
        BizResult bizResult = new BizResult();
        StringBuilder urlBuilder = new StringBuilder();

        String billingCycleId = bizParam.getParamString(BizConsts.RQUEST_KEY_BILLINGCYCLEID);
        String accNbr = bizParam.getParamString(BizConsts.RQUEST_KEY_ACCNBR);


        // 获取URL地址
        String url = bizParam.getParamString(BizConsts.KEY_ACCOUNT_API_URL);

        // 拼接get参数
        urlBuilder.append(url).append("?").append(BizConsts.RQUEST_KEY_ACCNBR).append("=").append(accNbr)
                .append("&").append(BizConsts.RQUEST_KEY_BILLINGCYCLEID).append("=").append(billingCycleId);

        String respStr = HttpClientUtils.getHttpStr(url, bizParam);


        if ("".equals(respStr)) {
            bizResult.setCode(BizConsts.STATUS_ACOUNT_API_FAIL);
            respStr = HttpClientUtils.getErrorJsonStr(BizConsts.STATUS_ACOUNT_API_FAIL, "", "", "");
        } else {
            bizResult.setCode(BizConsts.STATUS_ACOUNT_API_SUCCESS);
        }
        _log.info("Responding to external messages====:{}", respStr);
        bizResult.setHttpBody(respStr);

        return bizResult;
    }
}
